package com.quasar.hpatient.view.adapter;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.widget.Toolbar;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.litePalmodel.TroubleInfodb;
import com.quasar.hpatient.model.medicalmodel.DiscomfortData;
import com.quasar.hpatient.utils.LogAndToastUtil;
import com.quasar.hpatient.utils.Spanny;
import com.vise.log.ViseLog;

import java.util.List;

/**
 * author : 许建宏
 * Date: 2017/10/26 0026
 * View:时间列表
 */

public class EventAdapter extends BaseMultiItemQuickAdapter<DiscomfortData, BaseViewHolder> {

    public EventAdapter(List<DiscomfortData> data) {
        super(data);
        addItemType(DiscomfortData.HEAD, R.layout.widget_test_show);
        addItemType(DiscomfortData.BODY, R.layout.widget_test_show);
    }

    @Override
    protected void convert(BaseViewHolder helper, final DiscomfortData item) {
        final Spanny spanny = new Spanny();
        switch (helper.getItemViewType()) {
            case TroubleInfodb.HEAD:
                helper.setText(R.id.title, "日期");//检测时间
                helper.setText(R.id.msg, "不适症状");//检测时间
                helper.setText(R.id.msgcheck, "持续时间");//检测时间
                helper.setText(R.id.demo, "自述");//检测时间
                ViseLog.d("事件标题");
                break;

            case TroubleInfodb.BODY:
                if (item.getLogTime() != null) {
                    helper.setText(R.id.title, item.getLogTime().substring(0, item.getLogTime().length() - 3));//检测时间
                }

                helper.setText(R.id.msg, item.getTroubleName());//检测项
                TextView msgcheck = helper.getView(R.id.msgcheck);
                msgcheck.setText(item.getDurationLength());//不适时长

                if (item.getDescription() != null && item.getDescription().length() > 0) {
                    spanny.append("详情", new ForegroundColorSpan(color(R.color.btcolor)));
                } else {
                    spanny.append("详情", new ForegroundColorSpan(color(R.color.textcolor)));
                }
                helper.setText(R.id.demo, spanny);//检测值
                helper.addOnClickListener(R.id.demo);//全部
                helper.addOnClickListener(R.id.msgcheck);//全部
                helper.addOnLongClickListener(R.id.msg);
                break;

        }
    }

    private int color(int value) {
        return mContext.getResources().getColor(value);
    }
}
